const Router = require('koa-router');
const tool = require("../../tools/tool");
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");
router.post('/list/getRelBillById', async ctx => {
    try {
        let user = ctx.user
        let body = ctx.request.body
        let tenantId = user.tenantId;
        let cardId = body.cardId;
        let srcBillId = body.srcBillId;
        let srcTransType = body.srcTransType;
        let ret = {
            list2: [],
            list3: []
        };

        if ([153001, 153101].indexOf(srcTransType) !== -1) {
            ret.list2 = await db.query(`select * from v_invoice_receipt_detail where id=${srcBillId} and tenantId=${tenantId}`, {type: QueryTypes.SELECT})
        }
        else if ([150501, 150502, 150601, 150602, 150603].indexOf(srcTransType) !== -1) {
            ret.list2  = await db.query(`select * from v_invoice_detail where id=${srcBillId} and tenantId=${tenantId}`, {type: QueryTypes.SELECT})
        }
        else {
            let list2 = await db.query(`select * from v_invoice_other_detail where id=${srcBillId} and tenantId=${tenantId}`, {type: QueryTypes.SELECT})
            ret.list2 = list2;
        }
        ret.list3 = await db.query(`select * from v_card_detail where id=${cardId} and tenantId=${tenantId} order by price1 desc `, {type: QueryTypes.SELECT})
        return ctx.suc('', ret);
    } catch (e) {
        return ctx.err(e);
    }
})

module.exports = router;